import { getBrand, getCategory, getUnit } from "@/api/option"

const state = {
  brands: [],
  categories: [],
  units: []
};

const mutations ={
  SET_BRANDS: (state, data) => {
    state.brands = data;
  },
  SET_CATEGORIES: (state, data) => {
    state.categories = data;
  },
  SET_UNITS: (state, data) => {
    state.units = data;
  }
};

const actions = {
  getBrand({ commit }, query) {
    return new Promise((resolve, reject) => {
      getBrand(query)
        .then(res => {
          commit('SET_BRANDS', res.rows);
          resolve(res.rows);
        })
    })
  },
  getCategory({ commit }, query) {
    return new Promise((resolve, reject) => {
      getCategory(query)
        .then(res => {
          commit('SET_CATEGORIES', res.rows);
          resolve(res.rows);
        })
    })
  },
  getUnit({ commit }, query) {
    return new Promise((resolve, reject) => {
      getUnit(query)
        .then(res => {
          commit('SET_BRANDS', res.rows);
          resolve(res.rows);
        })
    })
  },
}
